package com.xintonghua.bussiness.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.AddProjectTypeBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 添加项目
 * Created by zhangxuemei on 2018/3/11.
 */

public class AddListProjectTypeAdapter extends BaseAdapter {
    private Context context;
    private List<AddProjectTypeBean> list;
    private String selectItem = "";

    public AddListProjectTypeAdapter(Context context, List<AddProjectTypeBean> list) {
        this.context = context;
        this.list = list;
    }

    public String getSelectItem() {
        return selectItem;
    }

    public void setSelectItem(String selectItem) {
        this.selectItem = selectItem;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public AddProjectTypeBean getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public List<AddProjectTypeBean> getList() {
        return list;
    }

    public void setList(List<AddProjectTypeBean> list) {
        this.list = list;
    }

    String fuwuxiangId;
    public String getFuwuXiangId()
    {
        return fuwuxiangId;
    }
    public void setFuwuXiangId(String xiangId)
    {
        this.fuwuxiangId=xiangId;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_add_list_project_type, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        AddProjectTypeBean bean = list.get(position);
        holder.tvTitle.setText(bean.getName());
        if (selectItem.equals(bean.getName())) {
            holder.tvTitle.setSelected(true);
            holder.tvTitle.setPressed(true);
            holder.linLay.setBackgroundResource(R.color.white);
        } else {
            holder.tvTitle.setSelected(false);
            holder.tvTitle.setPressed(false);
            holder.linLay.setBackgroundResource(R.color.grey_bg);
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.lin_lay)
        LinearLayout linLay;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
